﻿$(document).ready(function() {
    $('form').jqTransform();

    $("button").click(function() {

        $(".formError").hide();

    });
    var use_ajax = true;
    $.validationEngine.settings = {};

    $("form").validationEngine(
	{
	    //validationEventTriggers:"keyup blur",  //will validate on keyup and blur  
	    //inlineValidation: false,
	    promptPosition: "centerRight",
	    success: function() { use_ajax = true },
	    failure: function() { use_ajax = false; }
	})

    $("form").submit(function(e) {

        if (use_ajax) {            
            var autoGroupId = $("#autoGroup")[0].value;
            var license = $("#license")[0].value;
            var type = $("#type")[0].value;
            var size = $("#size")[0].value;          
            var heding = $("#heding")[0].value;
            var id = $("#id")[0].value;
            var sim = $("#sim")[0].value;

            var driver = $("#driver")[0].value;
  
            var drvice = $("#drvice")[0].value;
                        
            if(isNaN(sim)){
                alert("请选择Sim卡");return;
            }
            if(isNaN(driver)){
                alert("请选择从业人员");return;
            }
            if(isNaN(drvice)){
                alert("请选择设备");return;
            }
            
            
            var data1 = "COMMAND=" + encodeURIComponent($("#addOrEdit")[0].value);
            data1 += "&license=" + encodeURIComponent(license);
            data1 += "&type=" + encodeURIComponent(type);
            data1 += "&size=" + encodeURIComponent(size);
            data1 += "&autogroup=" + encodeURIComponent(autoGroupId);
            data1 += "&heding=" + encodeURIComponent(heding);
            data1 += "&id=" + encodeURIComponent(id);
            data1 += "&drvice=" + encodeURIComponent(drvice);
            data1 += "&driver=" + encodeURIComponent(driver);
            data1 += "&sim=" + encodeURIComponent(sim);
       
            jqPost("ajax/ajaxdump.aspx", data1, function(data, textStatus) {
                if ("autoAddSucc" == data) {
                    alert("添加成功");
                    var vGrid = parent._grid;
                    if (vGrid != null) {
                        vGrid.flexReload();
                    }

                    var vDoc = parent._my
                    if (vDoc != null) {
                        vDoc.unmask();
                    }
                    
                }
                else if ("autoEditSucc" == data) {
                    alert("编辑成功");
                    var vGrid = parent._grid;
                    if (vGrid != null) {
                        vGrid.flexReload();
                    }

                    var vDoc = parent._my
                    if (vDoc != null) {
                        vDoc.unmask();
                    }
                    
                    
                }
                else
                    alert("失败");
            }, function() {
                alert("失败");
            }, false, "json");
        }
        e.preventDefault();
    })
});